<!DOCTYPE HTML>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="__UI__/css/bs3/dpl.css" rel="stylesheet">
<link href="__UI__/css/bs3/bui.css" rel="stylesheet">
<link href="__UI__/css/page.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="__UI__/js/jquery-1.8.1.min.js"></script>
</head>
<body> 
<div class="container">
    <div class="search-grid-container">
		<div class="row">
			<div class="control-group">
				<form id="searchForm" class="form-horizontal">
					<div class="controls">
						<input type="text" class="control-text" name="search" id="search" data-tip="{text:'请输入脚本名称'}">
						<button type="button" id="btnSearch" class="button button-primary">查询脚本</button>
                        <button type="button" class="button button-info" id="cancel">清空查询</button>
					</div>
				</form>
                <!--<form id="J_Form" action="{:U('Home/Scripts/importdata')}" class="form-horizontal" method="post" enctype="multipart/form-data">
                    <div class="controls" style="float:right">
                        <input type="file" name="excel" id="file" />
                        <input name="uid" type="hidden" id="uid" value="{:session('gid')}">
                		<input name="mid" type="hidden" id="mid" value="{:session(C('AUTH_KEYS'))}">
                        <button type="submit" class="button button-primary">导入数据</button>
                    </div>
				</form>-->
			</div>
		</div>
    	<div id="grid"></div>
    </div>
</div>
<script type="text/javascript">

	$(function() {
		$('#importsss').uploadify({
			var uid = $("#uid").val();
			var mid = $("#mid").val();
			$.ajax({
				type:'post',
				url:'{:U("Home/Scripts/importdata")}',
				dataType:'json',
				data:{uid:uid, mid:mid},
				success:function(data){
					if(data.status == 'y'){
						BUI.Message.Alert('导入成功！');
					}else{
						BUI.Message.Alert('导入失败！');
					}
				}
			});
		});
	});
</script>
<script type="text/javascript" src="__UI__/js/bui.js"></script>
<!--<script type="text/javascript" src="__UI__/js/config.js"></script>-->
<script type="text/javascript">
	top.topManager.closePage('scripts_add');
	top.topManager.closePage('scripts_edit');
	BUI.use('common/page');
	BUI.use(['common/search','bui/overlay'],function (Search,Overlay){
		var columns = [
			{title:'脚本名称',dataIndex:'scriptsname',width:100},
			{title:'编辑',dataIndex:'',width:100,renderer:function(value,obj){
				var briefStr = Search.createLink({
					id:'scripts_edit',
					title:'脚本概述',
					text:'编辑概述&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;',
					href:'{:U("Home/Scripts/edit/id/' + obj.id + '")}',
					isClose:true,
				}),sceneStr = Search.createLink({
					id:'scene',
					title:'场景管理',
					text:'编辑场景&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;',
					href:'{:U("Home/Scene/index/sid/' + obj.id + '")}',
					isClose:true,
				}),
				copyStr = '<span class="grid-command btn-copy" title="类似创建">类似创建</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'
				delStr = '<span class="grid-command btn-del" title="脚本删除">删除</span>';
				Search.createLink;
				return briefStr + sceneStr + copyStr + delStr;
			}},
			{title:'演练',dataIndex:'',width:100,renderer:function(value,obj){
				var drillStr = Search.createLink({
					id:'signin',
					title:'演练签到',
					text:'进入演练&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;',
					href:'{:U("Home/Scripts/signin/did/1/sid/' + obj.id + '")}',
					isClose:false,
				});
				Search.createLink;
				return drillStr;
			}},
		],
		store = Search.createStore('{:U("Scripts/index")}',{
			proxy:{
				save:{removeUrl:'{:U("Scripts/index")}'}
			},
			autoSync:true,
			pageSize:10,
			
		}),
		gridCfg = Search.createGridCfg(columns,{
			forceFit:true,
			tbar:{
				items:[
					{text : '<i class="icon-refresh"></i>刷新页面',btnCls : 'button button-small',handler:function(){
						window.location.reload();
					}},
					{text : '<i class="icon-plus"></i>脚本新建',btnCls : 'button button-small',handler:function(){
						top.topManager.openPage({
							id:'scripts_add',
							title:'脚本新建',
							href:'{:U("Scripts/add")}',
							isClose:true,
						});
					}},
					{text:'<i class="icon-remove"></i>批量删除',btnCls:'button button-small',handler:delFunction},
				]
			},
			plugins:[BUI.Grid.Plugins.CheckSelection,BUI.Grid.Plugins.RowNumber] 
		});
		var search = new Search({
			store:store,
			gridCfg:gridCfg,
		}),
		grid = search.get('grid');
		function delFunction(){
			var selections = grid.getSelection();
			delItems(selections);
		}
		function delItems(items){
			var ids = [];
			BUI.each(items,function(item){
				ids.push(item.id);
			});
			if(ids.length){
				BUI.Message.Confirm('确认要删除选中的记录么？',function(){
					$.ajax({
						url:'{:U("Scripts/del")}',
						dataType:'json',
						data:{ids : ids},
						success:function(data){
							if(data.status == 'y'){
								search.load();
							}else{
								BUI.Message.Alert('删除失败！');
							}
						}
					});
				},'question');
			}
		}
		grid.on('cellclick',function(ev){
			var sender = $(ev.domTarget);
			if(sender.hasClass('btn-del')){
				var record = ev.record;
				delItems([record]);
			}
		});
		function copyFunction(){
			var selections = grid.getSelection();
			copyItems(selections);
		}
		function copyItems(items){
			var ids = [];
			BUI.each(items,function(item){
				ids.push(item.id);
			});
			if(ids.length){
				BUI.Message.Confirm('确认创建类似脚本',function(){
					$.ajax({
						url:'{:U("Scripts/copyindex")}',
						dataType:'json',
						data:{ids : ids},
						success:function(data){
							if(data.status == 'y'){
								//BUI.Message.Alert('创建成功！');
								BUI.Message.Alert(data.info);
								search.load();
							}else{
								BUI.Message.Alert('创建失败！');
							}
						}
					});
				},'question');
			}
		}
		grid.on('cellclick',function(ev){
			var sender = $(ev.domTarget);
			if(sender.hasClass('btn-copy')){
				var record = ev.record;
				copyItems([record]);
			}
		});

                var open_j = "{:session('open_j')}";
	        <if condition="session('open_j') eq 1"> 
                    var open_j_sid = {:session('open_j_sid')};
                    var open_j_pid = {:session('open_j_pid')}; 
                    top.topManager.openPage({
		            id:'drill',
			    href:'{:U("Scripts/drill/sid/' + open_j_sid + '/pid/' + open_j_pid + '")}',
			    title:'演练前凑'
			    
	            });   
                    $.ajax({
			   type:'post',
		       	   url:'{:U("Home/Session/edit_session")}',
			   success:function(data){
				 //alert(data);//测试数据使用
			   }
	            });
              </if>

	});
        //-----------	
	$(function () {       
		$('#cancel').click(function(){
			$("#search").attr("value",'');
		});
	});
	
	BUI.use('bui/form', function (Form) {
        new Form.Form({
            srcNode:'#J_Form'
        }).render();
    });

	$(function(){
		$('#import').click(function(){
			var u = $('#uid').val();
			var m = $('#mid').val();
			var f = $('#file').val();    
			if(f == ''){
				BUI.Message.Alert('请输入导入文件！');
			}else{
				$.ajax({
					type:'post',
					url:'{:U("Home/Department/import")}',
					dataType:'json',
					data:{title:t,uid:u,mid:m},
					success:function(data){
						if(data.status == 'y'){
							$('#file').attr("value",'')
							search.load();
						}else{
							BUI.Message.Alert('导入失败！');
						}
					}
				});
			}
		});
	});
</script>
</body>
</html>
